import Head from 'next/head';
import { signIn, signOut, useSession } from 'next-auth/react';
import styles from '../styles/Home.module.css';

const Session = () => {
  const { data: session } = useSession();
  if (session) {
    return (
      <>
        Signed in as {session.user.email} <br />
        <button onClick={() => signOut()}>Sign out</button>
      </>
    );
  }
  return (
    <>
      Not signed in <br />
      <button onClick={() => signIn()}>Sign in</button>
    </>
  );
};

export default function Home() {
  return (
    <div className={styles.container}>
      <Head>
        <title>GraphQL Yoga</title>
        <meta name="description" content="Generated by create next app" />
        <link rel="icon" href="/favicon.ico" />
      </Head>

      <main className={styles.main}>
        <h1 className={styles.title}>
          Welcome to <a href="https://nextjs.org">Next.js!</a>
        </h1>

        <p className={styles.description}>
          Edit the GraphQL Schema
          <a href="/api/graphql" target="_blank">
            <code className={styles.code}>pages/api/graphql.js</code>
          </a>
        </p>

        <Session />

        <div className={styles.grid}>
          <a href="https://nextjs.org/docs" className={styles.card}>
            <h2>Learn &rarr;</h2>
            <p>Learn about Next.js</p>
          </a>
          <a href="https://the-guild.dev/graphql/yoga-server" className={styles.card}>
            <h2>Learn &rarr;</h2>
            <p>Learn about GraphQL Yoga</p>
          </a>
        </div>
      </main>
    </div>
  );
}
